package com.leo;

import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * @ClassName View
 * @Description
 * @Author wangss
 * @date 2020.11.25 16:18
 * @Version 1.0
 */
public class View extends Stage {

    private Canvas canvas = new Canvas();

    public View() {
        Group root = new Group();
        root.getChildren().add(canvas);
        this.setScene(new Scene(root));
        this.setWidth(960.0);
        this.setHeight(540.0);
        this.show();

        canvas.widthProperty().bind(widthProperty());
        canvas.heightProperty().bind(heightProperty());
    }

    public void update() {
        canvas.getGraphicsContext2D().setFill(Color.RED);
        canvas.getGraphicsContext2D().fillRect(100, 100, 100, 100);
    }

    public void clear() {
        canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
    }
}
